package br.uniriotec.pssgbd.unterhaltung.model.dao;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.util.ArrayList;
import java.util.List;


import br.uniriotec.pssgbd.unterhaltung.model.entidade.relacionadaDegustacao.Combinacao;

public class CombinacaoDAO extends GenericDAO{
	
	private static String sqlSelect = "SELECT id_prato, id_rotulo FROM combinacao_degust";

	public List <Combinacao> obterCombinacoes(String sqlWhere, int cnpj_estab, Date data, Time hora) throws SQLException, ClassNotFoundException{
		this.criaConexao(false);

		String sqlCompleta = sqlSelect + sqlWhere;

		PreparedStatement stmt = null;
		ResultSet rs = null;
		Combinacao combinacao = null;
		List <Combinacao> combinacoes = new ArrayList <Combinacao>(); 

		try{
			stmt = getConnection().prepareStatement(sqlCompleta);
			stmt.setInt(1,cnpj_estab);
			stmt.setDate(2,data);
			stmt.setTime(3,hora);
			rs = stmt.executeQuery();
			if (rs.next()){
				combinacao = new Combinacao();
				combinacao.setId_prato(rs.getInt("id_prato"));
				combinacao.setId_rotulo(rs.getInt("id_rotulo"));
				combinacoes.add(combinacao);
				
			}

		}

		catch(SQLException e){
			throw e;
		}

		finally{
			try{
				stmt.close();
				rs.close();
				this.fechaConexao();
			} 
			catch (SQLException e) {
				throw e;
			}
		}

		return combinacoes;
	}
}


